<?php
namespace App\Services\Terrace;
use App\Models\Mysql\XnTerraceInfo;
class TerraceService
{
    public function all($name = '',$supplier_id)
    {
        $where[] = ['supplier_id','=',$supplier_id];
        $where[] = ['status','=',1];
        return XnTerraceInfo::where($where)
            -> with(['traceinfos'=>function($query) use($name){
                $query ->select('en','title','id');
                $query->when(!empty($name),function($query) use($name){
                    $query -> where('title','like','%'.$name.'%');
                });
            }])
            -> get()
            -> toArray();
    }

    public function update($app_id,$key,$url,$id){
        $arr = ['app_id'=>$app_id,'key'=>$key,'url'=>$url];
        XnTerraceInfo::where('sid','=',$id) -> update(['datas'=>json_encode($arr)]);
    }

}